<?php

class tinh extends database
{
	public function __construct(){ $this->connection(); }
    protected $_ten_tinh;
	protected $_id;

	public function set_id ($i) { $this->_id = $i; } 
	public function get_id () { return $this->_id; } 
    
	
    public function set_ten_tinh ($i) { $this->_ten_tinh = $i; } 
	public function get_ten_tinh () { return $this->_ten_tinh; }
    
    function get_auto_increment()
    {
        $sql = "SHOW TABLE STATUS WHERE name = 'tinh'";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            $row = $this->fetch();
            
            return $row['Auto_increment'];
        } else {
            return FALSE;
        }
    }
    
    public function insert_tinh()
    {
        $sql = "INSERT INTO tinh(ten_tinh) VALUES('" . $this->get_ten_tinh() . "')";
        $this->query($sql);
    }
    
    public function edit_tinh()
    {
        $sql = "UPDATE tinh SET ten_tinh=N'" . $this->get_ten_tinh() . "' WHERE id=N'" . $this->get_id() . "'";
        $this->query($sql);
    }
    
    public function delete_tinh()
    {
        $sql = "DELETE FROM tinh WHERE id='" . $this->get_id() . "'";
        $this->query($sql);
    }
    
    public function getbyall()
    {
        $sql = "SELECT * FROM tinh ORDER BY id DESC";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            while ($row = $this->fetch()) {
                $data[] = $row;
            }
            return $data;
        } else {
            return FALSE;
        }
    }
    
    public function getbyid()
    {
        $sql = "SELECT * FROM tinh WHERE id='" . $this->get_id() . "'";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            $row = $this->fetch();
            
            return $row;
        } else {
            return FALSE;
        }
    }
    
    public function total_num_rows()
    {
        $sql = "SELECT * FROM tinh";
        $this->query($sql);
        $total_num_rows = $this->num_rows();
        
        return $total_num_rows;
    }
    
    public function getbyoption($options = array())
    {
        $select   = isset($options['select']) ? $options['select'] : '*';
        $where    = isset($options['where']) ? 'WHERE' . $options['where'] : '';
        $order_by = isset($options['order_by']) ? 'ORDER BY ' . $options['order_by'] : '';
        $limit    = isset($options['offset']) && isset($options['limit']) ? 'LIMIT ' . $options['offset'] . ',' . $options['limit'] : '';
        $sql      = "SELECT $select FROM tinh $where $order_by $limit";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            while ($row = $this->fetch()) {
                $data[] = $row;
            }
            
            return $data;
        } else {
            return FALSE;
        }
    }
}

?>